layui.use(['laytpl', 'table', 'element', 'upload', 'jquery', 'layer', 'laydate'], function() {
    var table = layui.table;
    var element = layui.element;
    var upload = layui.upload;
    var laydate = layui.laydate;
    var laytpl = layui.laytpl;
    var $ = layui.jquery;
    var layer = layui.layer;
    localStorage.removeItem('fixedUser')
    var form = layui.form;

    // 导入数据入口
    importWrap = function () {
        $('#importBtn').click();
    }
    // 导入数据
    var importParam = $.extend({}, publicData);
    importParam.parkId = 107298;
    importParam.file = "xls";
    importParam.isIE = 0;

    var uploadMsg;
    var uploadInst = upload.render({
        elem: '#importBtn', //绑定元素
        url: httpUrl + '/admin/vehicle/addExcelTemplateData',
        data: importParam,
        accept: 'file',
        size: 1024,
        before: function (o) {
            uploadMsg = layer.msg('上传中', {
                icon: 16, shade: [0.1, '#fff'], time: false
            });
        },
        done: function (res) {
            console.log("done")
            if (res.returnCode === 'SUCCESS') {
                if (res.data === 0) {
                    layer.msg(res.returnMsg, {
                        icon: 1
                    });
                } else {
                    layer.msg(res.returnMsg, {
                        icon: 2
                    });
                    exportFailedData()
                }

                allData(queryVehicleByPage)
            } else {
                if (res.returnCode === 'UNAUTHORIZED') {
                    checkToken();
                } else {
                    layer.msg(res.returnMsg, {
                        icon: 2
                    });
                }
            }
            layer.close(uploadMsg);
        },
        error: function (res) {
            console.log(res);
            layer.msg('网络异常', {
                icon: 2
            });
            layer.close(uploadMsg);
        }
    });

    // 下载模板
    exportData = function () {
        var userAgent = window.navigator.userAgent;
        var exportData = {};
        if (userAgent.indexOf('Firefox') !== -1) {
            exportData.isIE = 0;
        } else {
            exportData.isIE = 1;
        }
        var URL = httpUrl + '/admin/vehicle/excelTemplateDownload';
        download(exportData, URL, '固定用户导入模板');
    }

    // 导出
    exportDatas = function () {
        let userAgent = window.navigator.userAgent;
        let exportParam = {};
        if (userAgent.indexOf('Firefox') !== -1) {
            exportParam.isIE = 0;
        } else {
            exportParam.isIE = 1;
        }
        exportParam.isOpenPage = false;
        let URL = httpUrl + '/admin/vehicle/vehicleExcelExport';
        download(exportParam, URL, '固定用户管理');
    }

    // 下载导入失败数据
    exportFailedData = function () {
        let userAgent = window.navigator.userAgent;
        let exportData = {};
        if (userAgent.indexOf('Firefox') !== -1) {
            exportData.isIE = 0;
        } else {
            exportData.isIE = 1;
        }
        exportData.parkId = 107298;
        let URL = httpUrl + '/admin/vehicle/failedExcelExport';
        download(exportData, URL, '固定用户导入失败数据');
    }

});